package com.atwork.wuhua.dialog;

import android.content.Context;

import com.atwork.wuhua.R;
import com.zyao89.view.zloading.ZLoadingDialog;
import com.zyao89.view.zloading.Z_TYPE;

public class LoadingDailog {

    private static volatile LoadingDailog singleton;
    private static ZLoadingDialog dialog;

    private LoadingDailog() {
    }

    public static LoadingDailog getInstance(Context context) {
        if (singleton == null) {
            synchronized (LoadingDailog.class) {
                if (singleton == null) {
                    singleton = new LoadingDailog();
                }
            }
        }
        init(context);
        return singleton;
    }

    private static void init(Context context) {
        dialog = new ZLoadingDialog(context);
        dialog.setLoadingBuilder(Z_TYPE.ROTATE_CIRCLE)//设置类型
                .setLoadingColor(context.getResources().getColor(R.color.A3b94fb))//颜色
//                .setHintText("Loading...")
                .setHintTextSize(16) // 设置字体大小 dp
                .setHintTextColor(context.getResources().getColor(R.color.white))  // 设置字体颜色
                .setDurationTime(0.5) // 设置动画时间百分比 - 0.5倍
                .setCancelable(false)
                .setDialogBackgroundColor(context.getResources().getColor(R.color.A000)); // 设置背景色，默认白色
    }

    public static void show() {
        if (dialog != null) {
            dialog.setCanceledOnTouchOutside(true);
            dialog.show();
        }
    }

    public static void show(String text) {
        if (dialog != null) {
            dialog.setHintText(text);
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        }
    }

    public static void dismiss() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }
}
